{extend name="../../base/view/common/base" /}
{block name="style"}
<style>
.layui-table-1 .tr-2,.layui-table-1 .tr-3{display:none;}
.layui-table-2 .tr-1,.layui-table-2 .tr-3{display:none;}
.layui-table-3 .tr-1,.layui-table-3 .tr-2{display:none;}
.layui-table-4 .tr-1,.layui-table-4 .tr-2,.layui-table-4 .tr-3,.layui-table-4 .tr-4{display:none;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	{if condition="$id eq 0"}
	<h3 class="pb-3">新建消息</h3>
	<table id="messageTable" class="layui-table layui-table-form layui-table-1">
		<tr>
			<td class="layui-td-gray-2">接收人类型</td>
			<td>
				<input type="radio" name="types" lay-filter="types" value="1" title="同事" checked>
				<input type="radio" name="types" lay-filter="types" value="2" title="部门">
				<input type="radio" name="types" lay-filter="types" value="3" title="岗位">
				<input type="radio" name="types" lay-filter="types" value="4" title="全部">
			</td>
		</tr>
		<tr class="tr-1">
			<td class="layui-td-gray">收件人<font>*</font></td>
			<td>
				<input type="text" name="unames" value="" placeholder="请选择收件人" readonly class="layui-input picker-admin" data-type="2">
				<input type="hidden" name="uids" value="">
			</td>
		</tr>
		<tr class="tr-2">
			<td class="layui-td-gray">收件部门<font>*</font></td>
			<td>
				<input type="text" name="dnames" value="" placeholder="请选择收件部门" readonly class="layui-input picker-oa" data-types="department" data-type="2">
				<input type="hidden" name="dids" value="">
			</td>
		</tr>
		<tr class="tr-3">
			<td class="layui-td-gray">收件岗位<font>*</font></td>
			<td>
				<input type="text" name="pnames" value="" placeholder="请选择收件岗位" readonly class="layui-input picker-oa" data-types="position" data-type="2"">
				<input type="hidden" name="pids" value="">
			</td>
		</tr>
		<tr class="tr-4">
			<td class="layui-td-gray">抄送人</td>
			<td>
				<input type="text" name="copy_names" value="" placeholder="请选择抄送人" readonly class="layui-input picker-admin" data-type="2">
				<input type="hidden" name="copy_uids" value="">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">消息主题<font>*</font></td>
			<td><input type="text" name="title" value="" lay-verify="required" lay-reqText="请输入消息主题" placeholder="请输入消息主题" class="layui-input" lay-verify="required"></td>
		</tr>
		<tr>
			<td class="layui-td-gray">消息内容<font>*</font></td>
			<td><textarea name="content" placeholder="请输入消息内容" class="layui-textarea" style="height: 200px;" lay-verify="required" lay-reqText="请输入消息内容"></textarea></td>
		</tr>
		<tr>
			<td class="layui-td-gray"><div class="layui-input-inline">附件</div> <div class="layui-input-inline"><button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></div></td>
			<td>
				<div class="layui-row" id="uploadBox">
					<input type="hidden" data-type="file" name="file_ids" value="">
				</div>
			</td>
		</tr>
	</table>
	{else/}
	<h3 class="pb-3">编辑消息</h3>
	<table id="messageTable" class="layui-table layui-table-form layui-table-{$detail.types}">
		<tr>
			<td class="layui-td-gray-2">接收人类型</td>
			<td>
				<input type="radio" name="types"  lay-filter="types" value="1" title="同事" {eq name="$detail.types" value="1"}checked{/eq}>
				<input type="radio" name="types"  lay-filter="types" value="2" title="部门" {eq name="$detail.types" value="2"}checked{/eq}>
				<input type="radio" name="types"  lay-filter="types" value="3" title="岗位" {eq name="$detail.types" value="3"}checked{/eq}>
				<input type="radio" name="types"  lay-filter="types" value="4" title="全部" {eq name="$detail.types" value="4"}checked{/eq}>
			</td>
		</tr>
		<tr class="tr-1">
			<td class="layui-td-gray">收件人<font>*</font></td>
			<td>
				<input type="text" name="unames" value="{$detail.unames|default=''}" placeholder="请选择收件人" readonly class="layui-input picker-admin" data-type="2">
				<input type="hidden" name="uids" value="{$detail.uids|default=''}">
			</td>
		</tr>
		<tr class="tr-2">
			<td class="layui-td-gray">收件部门<font>*</font></td>
			<td>
				<input type="text" name="dnames" value="{$detail.dnames|default=''}" placeholder="请选择收件部门" readonly class="layui-input picker-oa" data-types="department" data-type="2">
				<input type="hidden" name="dids" value="{$detail.dids|default=''}">
			</td>
		</tr>
		<tr class="tr-3">
			<td class="layui-td-gray">收件岗位<font>*</font></td>
			<td>
				<input type="text" name="pnames" value="{$detail.pnames|default=''}" placeholder="请选择收件岗位" readonly class="layui-input picker-oa" data-types="position" data-type="2"">
				<input type="hidden" name="pids" value="{$detail.pids|default=''}">
			</td>
		</tr>
		<tr class="tr-4">
			<td class="layui-td-gray">抄送人</td>
			<td>
				<input type="text" name="copy_names" value="{$detail.copy_names|default=''}" placeholder="请选择抄送人" readonly class="layui-input picker-admin" data-type="2">
				<input type="hidden" name="copy_uids" value="{$detail.copy_uids|default=''}">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">消息主题<font>*</font></td>
			<td><input type="text" name="title" value="{$detail.title|default=''}" lay-verify="required" lay-reqText="请输入消息主题" placeholder="请输入消息主题" class="layui-input" lay-verify="required"></td>
		</tr>
		<tr>
			<td class="layui-td-gray">消息内容<font>*</font></td>
			<td>
				<textarea name="content" placeholder="请输入消息内容" class="layui-textarea" style="height: 200px;" lay-verify="required" lay-reqText="请输入消息内容">{$detail.content|default=''}</textarea>
				{if condition="($detail.msg_id > 0)"}		
				<table class="layui-table" style="margin-top:10px">
				<tr>
					<td class="layui-td-gray-2">引用消息内容</td>
					<td>{$detail.from_content}</td>
				</tr>
				{notempty name="$detail.from_file_array"}
				<tr>
					<td class="layui-td-gray" style="vertical-align:top">引用消息附件</td>
					<td>
						<div class="layui-row">
							{volist name="$detail.from_file_array" id="vo"}
							<div class="layui-col-md4" id="uploadFile{$vo.id}">{:file_card($vo,'view')}</div>
							{/volist}
						</div>
					</td>
				</tr>
				{/notempty}
				</table>
				{/if}
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray"><div class="layui-input-inline">附件</div> <div class="layui-input-inline"><button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></div></td>
			<td colspan="5">
				<div class="layui-row" id="uploadBox">
					<input type="hidden" name="file_ids" data-type="file" value="{$detail.file_ids}">
					{notempty name="$detail.file_ids"}
					{volist name="$detail.file_array" id="vo"}
					<div class="layui-col-md4" id="uploadFile{$vo.id}">{:file_card($vo)}</div>
					{/volist}
					{/notempty}
				</div>
			</td>
		</tr>
	</table>
	{/if}
	<div class="pt-4">
		<input type="hidden" value="{$id}" name="id">
		<input type="hidden" value="{$msg_id}" name="msg_id">
		<button class="layui-btn" lay-submit="" lay-filter="draftform">存为草稿</button>
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即发送</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','oaPicker','uploadPlus'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,uploadPlus=layui.uploadPlus;
		let uploada = new uploadPlus();
		//监听保存到草稿并发送
		form.on('submit(webform)', function(data){
			data.field.is_draft=1;
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			let clickbtn = $(this);
			tool.post("/home/message/save", data.field, callback,clickbtn);
			return false;
		});
		  
		//监听保存到草稿
		form.on('submit(draftform)', function(data){
			data.field.is_draft=2;
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			let clickbtn = $(this);
			tool.post("/home/message/save", data.field, callback),clickbtn;
			return false;
		});

		//选择收件人类型
		form.on('radio(types)', function (data) {
			$('#messageTable').attr('class','layui-table layui-table-form layui-table-'+data.value);
		});		
	}		
	</script>
{/block}
<!-- /脚本 -->